# https://quality-tools.maycur.com/teambition_script/task?task_id=67f736abfb00e2670c006734
import requests

# from requests_cache import CachedSession


# 获取任务详情
def getTaskDetail(task_id):
    data = None
    res = requests.get(
        "https://quality-tools.maycur.com//teambition_script/task?task_id=" + task_id
    )
    if res.status_code == 200:
        d = res.json()["data"]["results"]
        if d:
            data = d[0]
    else:
        print(
            "getTaskDetail fail "
            + "code="
            + str(res.status_code)
            + " task_id="
            + task_id
        )
    return data


# 获取迭代任务列表
def fetchSprintData(sprintList):
    data = []
    for sprint in sprintList:
        res = requests.get(
            "https://quality-tools.maycur.com//teambition_script/sprint/task/?name="
            + sprint
        )
        if res.status_code == 200:
            d = res.json()["data"]["results"]
            data.extend(d)
        else:
            print(res.status_code)
    return data


# 获取任务关联列表
def fetchTaskLink(task_id):
    data = []
    res = requests.get(
        "https://quality-tools.maycur.com/teambition_script/task/link/?task_id="
        + task_id
    )
    if res.status_code == 200:
        data = res.json()["data"]["results"]
    else:
        print(res.status_code)
    return data


def fetchTasksView(period):
    # only limit 100 tasks
    data = []
    res = None
    if period == "this_year":
        res = requests.get(
            "https://quality-tools.maycur.com//teambition_script/smartgroup/task/?project_id=5e18291b91d57a001a5797d4&name=今年客成需求统筹&page_size=1000"
        )
    elif period == "30d":
        res = requests.get(
            "https://quality-tools.maycur.com//teambition_script/smartgroup/task/?project_id=5e18291b91d57a001a5797d4&name=过去30天客成需求&page_size=1000"
        )
    if res:
        data = res.json()["data"]["results"]
    return data
